-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic support for new-in-initializer #238
base: 1.23.x
Are you sure you want to change the base?
Conversation
Do you see this somehow being useful for the analysis, or is it just because we don't have a different syntax for "let's make this parameter optional but not nullable"? One thing this will impact are types resolved for generics and conditional types (that should be tested), but otherwise not much imho. |
Could you explain what this has to do with optional or non-nullable parameters?
While this is true, for default values in regular code generics aren't taken into account either. So implementing this in PHPStan itself is just a few lines of code. |
They are: https://phpstan.org/r/fe352005-91ed-4021-bd95-9d6df9f886a4 (and not generalized on bleeding edge https://phpstan.org/r/7fad672b-f8b0-4128-9282-d82a6599f2b6, unless in GenericObjectType). |
I don't really get the question, because the answer is "everything"? This syntax applies only to default value of parameters in |
Ah, I actually meant that the default value itself is never generic: https://phpstan.org/r/dc1fee3f-b8de-448d-ba24-edc733770921 I think I understand what you're trying to figure out, and I think the short answer is: this is only to indicate that such a parameter has a default value, which is impossible otherwise right now. Not really relevant for analysis. But this is nice and simple and mirrors the native syntax precisely. :) |
I agree. I just wanted to show the test with generics should be added in PHPStan to show we're actually reading the default value correctly. And if the class in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs some changes in Printer too. At least definitely a one in $listInsertionMap
and maybe more.
Not all entries in that property are tested, but if you comment ArrayShapeNode::class . '->items' => ', ',
you'll see the kind of test I'd like to see. It's somewhere around $addItemsToArrayShape
in PrinterTest. Thanks!
4c28423
to
cb43a7f
Compare
Implementation for #173